package utilities;

import java.util.Calendar;

public class Logger {
	
	private String cn;
	private static LoggerLevel currentLogL= LoggerLevel.DEBUG;
	
	private Logger(String classname) {
		cn = classname;
	}
	
	public static Logger getLogger(@SuppressWarnings("rawtypes") Class c) {
		return new Logger(c.getSimpleName().toString());
	}
	
	public static void setLoggerLevel(LoggerLevel newLogL) {
		currentLogL = newLogL;
	}
	
	public void d(String msg) {
		if (currentLogL.getLevel() <= LoggerLevel.DEBUG.getLevel()) {
			log(msg,LoggerLevel.DEBUG);
		}
	}
	
	public void i(String msg) {
		if (currentLogL.getLevel() <= LoggerLevel.INFO.getLevel()) {
			log(msg,LoggerLevel.INFO);
		}
	}
	
	public void w(String msg) {
		if (currentLogL.getLevel() <= LoggerLevel.WARNING.getLevel()) {
			log(msg,LoggerLevel.WARNING);
		}
	}
	public void e(String msg) {
		if (currentLogL.getLevel() <= LoggerLevel.ERROR.getLevel()) {
			log(msg,LoggerLevel.ERROR);
		}
	}
	
	private void log(String msg, LoggerLevel logL) {
		System.out.println("["+logL+"] "+Calendar.getInstance().getTime()+" - {"+cn+"} "+ msg);
	}
	
	public void plain(String msg) {
		System.out.println(msg);
	}
	
	public enum LoggerLevel {
		DEBUG (0," DEBUG "),
		INFO (1," INFO  "),
		WARNING (2,"WARNING"),
		ERROR (3," ERROR ");		
		
		private final int level;
		private final String name;
		
		private LoggerLevel(int level, String name) {
			this.level = level;
			this.name = name;
		}
		
		public final int getLevel() {
			return level;
		}
		
		@Override
		public final String toString() {
			return name;
		}
	}

}
